home *** CD-ROM | disk | FTP | other *** search
- /*
- * catalog.c - routines associated with accessing Mac directory
- * catalogs and manipulating the cat_node structures.
- */
-
- #include "RevRdist.h"
- #include <unix.h>
- #include <TransSkelProto.h>
- #include <TransDisplayProto.h>
-
- extern void lastpart (StringPtr);
-
-
- /*
- *=========================================================================
- * freeList (l) - free cat_node list
- * entry: l = head of cat_node list to be freed
- * exit: all nodes in list returned to memory pool
- *=========================================================================
- */
-
- void
- freeList (l)
- cnode_t *l;
- {
- cnode_t *n;
-
- while (l)
- {
- n = l->link; /* remember next node */
- DisposPtr ((Ptr)l); /* free this node */
- l = n;
- }
- }
-
-
-
- /*
- *=========================================================================
- * getInfo (name, vol, dirID, cp) - get catalog info about named file/folder
- * entry: name = ptr to name of file/folder to get info about
- * vol = VRefNum where file/folder resides
- * dirID = directory ID name is a partial path relative to
- * cp = ptr to cnode_t to put catalog information into
- * returns: 0 if no error, else OSErr
- *=========================================================================
- */
- OSErr
- getInfo (name, vol, dirID, cp)
- StringPtr name;
- Integer vol;
- Longint dirID;
- cnode_t * cp;
- {
- CInfoPBRec ci;
- OSErr error;
- Str255 s;
-
- ZERO (ci);
- COPYPS (name, s);
- ci.hFileInfo.ioNamePtr = s;
- ci.hFileInfo.ioVRefNum = vol;
- ci.hFileInfo.ioDirID = dirID;
- if (error = PBGetCatInfo (&ci, false))
- return error;
- lastpart (s);
- saveCatInfo (&ci, cp);
- return 0;
- }
-
-
-
- /*
- *=========================================================================
- * listFolder (vol, dir) - build cat_node list of folder
- * entry: vol = volume refnum for folder
- * dir = directory id within vol of folder to catalog
- * returns: ptr to cat_node list of files and folders in dir, list is
- * in alphabetical order
- * NULL if cannot. ClueID set to STR# number of reason.
- *=========================================================================
- */
-
- cnode_t *
- listFolder (vol, dir)
- Integer vol;
- Longint dir;
- {
- OSErr error;
- int idx; /* index into folder */
- int len; /* name length */
- cnode_t *cur, *node, *prev; /* pointers into list */
- register CInfoPBPtr cp; /* ptr to catalog entry */
- HParamBlockRec pb; /* param block for file sys calls */
- cnode_t head; /* dummy head of list */
- Str255 name; /* current entry name */
-
- prev = cur = &head;
- cp = (CInfoPBPtr) &pb;
- ClueID = 0;
- Clue0 = (SP) "\plistFolder";
- ZERO (head);
- ZERO (pb);
- pb.fileParam.ioNamePtr = name;
- /*
- * Call GetCatInfo until we run out of directory entries
- */
- for (idx = 1, error = 0; !error && !Quit; idx++)
- {
- name[0] = 0; /* specify entry by idx */
- cp->hFileInfo.ioVRefNum = vol;
- cp->hFileInfo.ioFDirIndex = idx;
- cp->hFileInfo.ioDirID = dir;
- error = PBGetCatInfo (cp, false);
- if (error)
- {
- Clue1 = (SP) "\pPBGetCatInfo";
- break;
- }
- len = name[0];
- if (len == 0 || len > 31)
- continue; /* should not happen */
- /*
- * allocate a new node and copy information to it
- */
- node = (cnode_t *) NewPtr (sizeof (* node));
- if (!node)
- {
- Clue1 = (SP) "\pNewPtr";
- error = MemError ();
- if (error == 0)
- error = memFullErr;
- break;
- }
- ZEROAT(node);
- saveCatInfo (cp, node);
- /*
- * Insertion sort the name into current cat_list.
- * Mac file system catalogs are already in the correct order,
- * so start at the front only if the new name is before the
- * previous one.
- */
- if (RelString (name, prev->name, false, true) < 0)
- prev = cur = &head;
- for (; cur; prev = cur, cur = prev->link)
- if (RelString (name, cur->name, false, true) < 0)
- break;
- node->link = cur;
- prev->link = node;
- prev = node;
- }
- node = head.link;
- if (error && error != fnfErr)
- {
- ClueID = error;
- freeList (node);
- node = nil;
- }
- if (!error && Quit)
- {
- freeList (node);
- node = nil;
- }
- return node;
- }
-
-
- /*
- *=========================================================================
- * saveCatInfo (cp, node) - save catalog information in catalog node
- * entry: cp = ptr to CInfoPBRec with information
- * node = ptr to catalog node to copy information to
- *=========================================================================
- */
- void
- saveCatInfo (cp, node)
- register CInfoPBRec * cp;
- register cnode_t * node;
- {
- register StringPtr name;
-
- name = cp->hFileInfo.ioNamePtr;
- if (name)
- {
- if (name[0] > 31)
- {
- panic (false, E_NAMELEN, (SP)"\psaveCatInfo", name, nil);
- if (Quit)
- return;
- name[0] = 31;
- }
- COPYPS (name, node->name);
- }
- if (cp->hFileInfo.ioFlAttrib & 0x10)
- {
- /* folder */
- node->ctype = C_FOLDER;
- node->dirID = cp->dirInfo.ioDrDirID;
- node->crDate = cp->dirInfo.ioDrCrDat;
- node->mdDate = cp->dirInfo.ioDrMdDat;
- node->parID = cp->dirInfo.ioDrParID;
- node->in.d.dinfo = cp->dirInfo.ioDrUsrWds;
- node->in.d.frScroll = cp->dirInfo.ioDrFndrInfo.frScroll;
- node->in.d.frOChain = cp->dirInfo.ioDrFndrInfo.frOpenChain;
- node->attrib = cp->dirInfo.ioFlAttrib;
- node->access = cp->dirInfo.ioACUser;
- }
- else
- {
- /* file */
- node->ctype = C_FILE;
- node->dirID = cp->hFileInfo.ioDirID;
- node->parID = cp->hFileInfo.ioFlParID;
- node->crDate = cp->hFileInfo.ioFlCrDat;
- node->mdDate = cp->hFileInfo.ioFlMdDat;
- node->in.f.fileLen = cp->hFileInfo.ioFlLgLen;
- node->in.f.rsrcLen = cp->hFileInfo.ioFlRLgLen;
- node->in.f.finfo = cp->hFileInfo.ioFlFndrInfo;
- node->attrib = cp->hFileInfo.ioFlAttrib;
- node->access = cp->hFileInfo.ioACUser;
- }
- }